/* Copyright 2009 Requirements Management System  *  * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.mags.remas.view.dialogs;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.vafada.swtcalendar.SWTCalendar;
import org.vafada.swtcalendar.SWTCalendarListener;import java.util.Calendar;import java.util.Date;import org.mags.remas.view.commons.ImageProvider;
/** *  * @author Mario Gaitan * */
public class CalendarDialog {
    private Shell shell;
    private SWTCalendar swtcal;
    private Display display;
    public CalendarDialog(Display display) {
        this.display = display;
        shell = new Shell(display, SWT.APPLICATION_MODAL|SWT.CLOSE);        shell.setLayout(new RowLayout());        shell.setImage(ImageProvider.getCommonImage("calendar.png"));        swtcal = new SWTCalendar(shell);
    }    public void close() {    	shell.close();    }
    public void open() {
        shell.pack();        Rectangle screen = display.getPrimaryMonitor().getBounds();        Rectangle window = shell.getBounds();        int x = screen.x + (screen.width-window.width)/2;        int y = screen.y + (screen.height-window.height)/2;        shell.setLocation(x, y);                
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) display.sleep();
        }
    }
    public Calendar getCalendar() {
        return swtcal.getCalendar();
    }
    public void setDate(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        swtcal.setCalendar(calendar);
    }
    public void addDateChangedListener(SWTCalendarListener listener) {
        swtcal.addSWTCalendarListener(listener);
    }
}
